import { ref } from 'vue';

export default function useVeeValidate() {
  const loginForm = ref({
    username: 'LDG_Sunday',
    password: '123123'
  });
  const validateUsername = (inputVal: unknown): boolean | string => {
    if (typeof inputVal !== 'string' && inputVal == null) {
      return '用户名不能为空';
    }

    if (!inputVal) {
      return '用户名不能为空';
    }

    if (typeof inputVal === 'string') {
      if (inputVal.length < 3 || inputVal.length > 12) {
        return '用户名长度必须在3-12位之间';
      }
    }

    return true;
  };

  const validatePassword = (inputVal: unknown): boolean | string => {
    if (typeof inputVal !== 'string' && inputVal == null) {
      return '密码不能为空';
    }

    if (!inputVal) {
      return '密码不能为空';
    }

    if (typeof inputVal === 'string') {
      if (inputVal.length < 6 || inputVal.length > 12) {
        return '密码长度必须在6-12位之间';
      }
    }

    return true;
  };

  const onLoginHandler = () => {};

  return {
    loginForm,
    validateUsername,
    validatePassword,
    onLoginHandler
  };
}
